﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Views_CargoSize : System.Web.UI.Page
{
    DataSet ds = null;
    static int iCount = 0;
    int _SLine = 0;
    int _SLcol = 0;
    int _ELine = 0;
    int _ELcol = 0;
    int iLine = 0;
    int iLcol = 0;

    int iMessage = 0;

    Nova_BLL.TSysoption Nova_BLL_TSysoption = new Nova_BLL.TSysoption();
    Nova_BLL.TLaneDefine Nova_BLL_TLaneDefine = new Nova_BLL.TLaneDefine();
    Nova_BLL.TBase_Position Nova_BLL_TBase_Position = new Nova_BLL.TBase_Position();
    Nova_MOD.TBase_Position Nova_MOD_TBase_Position = new Nova_MOD.TBase_Position();

    protected void Page_Load(object sender, EventArgs e)
    {
        gvType_Size_Bind();
        if (!IsPostBack)
        {
            ddlNo_Lane_Bind();
            ddlType_Size_Bind();
            //gv_Style_Size();
            gv_Size_Bind();
        }
    }

    /// <summary>
    /// 绑定gv显示颜色
    /// </summary>
    protected void gvType_Size_Bind()
    {
        ds = Nova_BLL_TSysoption.DataListTSysoption(109);
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            gvType_Size.DataSource = ds;
            gvType_Size.DataBind();
        }
    }


    protected void gvType_Size_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    Label labValuefloat = (Label)e.Row.Cells[2].FindControl("labValuefloat");
        //    labValuefloat.BackColor = System.Drawing.Color.FromName(labValuefloat.ToolTip.ToString());
        //}
    }

    /// <summary>
    /// 绑定下拉列表
    /// </summary>
    protected void ddlType_Size_Bind()
    {
        ds = Nova_BLL_TSysoption.DataListTSysoptionSize(109,1);
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            ddlType_Size.DataSource = ds;
            ddlType_Size.DataBind();
        }
    }

    protected void ddlType_Size_DataBound(object sender, EventArgs e)
    {
        ddlType_Size.Items.Insert(0, new ListItem("-请选择-", "-1"));
    }

    /// <summary>
    /// gv宽度和高度
    /// </summary>
    //protected void gv_Style_Size()
    //{
    //    HttpCookie cookies = Request.Cookies["vNovaUserNo"];
    //    ds = Nova_BLL_TBase_Position.getGVStyle("TSysoption_Size", cookies.Value);
    //    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
    //    {
    //        txtWidth_Size.Text = ds.Tables[0].Rows[0]["Width"].ToString();
    //        txtHeight_Size.Text = ds.Tables[0].Rows[0]["Height"].ToString();
    //        gv_Size.Width = Unit.Parse(ds.Tables[0].Rows[0]["Width"].ToString());
    //        gv_Size.Height = Unit.Parse(ds.Tables[0].Rows[0]["Height"].ToString());
    //    }
    //}

    /// <summary>
    /// 宽度和高度取消
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void ibtnCancel_Size_Click(object sender, ImageClickEventArgs e)
    //{
    //    gv_Style_Size();
    //}
    /// <summary>
    /// 宽度和高度确定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void ibtnOk_Size_Click(object sender, ImageClickEventArgs e)
    //{
    //    HttpCookie cookies = Request.Cookies["vNovaUserNo"];
    //    int iFlag = Nova_BLL_TBase_Position.iBackGVStyle(txtWidth_Size.Text.ToString(), txtHeight_Size.Text.ToString(), "TSysoption_Size", cookies.Value);
    //    if (iFlag > 0)
    //    {
    //        gv_Size.Width = Unit.Parse(txtWidth_Size.Text.ToString());
    //        gv_Size.Height = Unit.Parse(txtHeight_Size.Text.ToString());
    //    }
    //}

    /// <summary>
    /// 绑定gv
    /// 20200518 修改 直接绑定gv 显示的字符 Sp_TypeOfSizePosition_New 代替： Sp_TypeOfSizePosition 
    /// </summary>
    public void gv_Size_Bind()
    {
        ds = Nova_BLL_TSysoption.TSysoptionList_Size("Sp_TypeOfSizePosition_New", ddlNo_Lane.SelectedValue);
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            gv_Size.DataSource = ds;
            gv_Size.DataBind();
            iCount = ds.Tables[0].Columns.Count;
        }
    }

    /// <summary>
    /// 每行绑定 点击行行触发SelectedIndexChanging事件（SelectedIndexChanging 不能自动触发）
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gv_Size_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        #region  原有的行绑定注释 （每个货位加载显示的颜色、加载点击属性，导致页面太卡） 
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    //e.Row.Cells[2].Text = "?";
        //    int rid = e.Row.RowIndex + 1;
        //    string strColor = "";
        //    for (int i = 2; i < e.Row.Cells.Count; i++)
        //    {
        //        e.Row.Cells[i].ToolTip = e.Row.Cells[i].Text;

        //        strColor = Nova_BLL_TSysoption.getColor(109, Convert.ToInt16(e.Row.Cells[i].ToolTip.ToString()));
        //        if (strColor != null && strColor != "")
        //        {
        //            e.Row.Cells[i].BackColor = System.Drawing.Color.FromName(strColor);
        //        }
        //        e.Row.Cells[i].Text = "";


        //        //巷道
        //        Nova_MOD_TBase_Position.No_Lane = Convert.ToInt32(ddlNo_Lane.SelectedValue);
        //        //排
        //        Nova_MOD_TBase_Position.No_Line = Convert.ToInt32(e.Row.Cells[0].Text.ToString());
        //        //列
        //        Nova_MOD_TBase_Position.No_Col = i - 1;     //列从1开始
        //        //Nova_MOD_TBase_Position.No_Col = i ; //列从2开始
        //        //层
        //        Nova_MOD_TBase_Position.No_Layer = Convert.ToInt32(e.Row.Cells[1].Text.ToString());

        //        e.Row.Cells[i].Attributes["onclick"] = "ShowEdit(" + Nova_MOD_TBase_Position.No_Lane + "," + Nova_MOD_TBase_Position.No_Line + "," + Nova_MOD_TBase_Position.No_Col + "," + Nova_MOD_TBase_Position.No_Layer + "," + rid + ");";
        //    }
        //}
        #endregion

        //每行绑定  点击行行触发SelectedIndexChanging事件（SelectedIndexChanging 不能自动触发）
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["style"] = "cursor:hand";

            #region   //点击行触发SelectedIndexChanging事件
            PostBackOptions myPostBackOptions = new PostBackOptions(this);
            myPostBackOptions.AutoPostBack = false;
            myPostBackOptions.PerformValidation = false;
            myPostBackOptions.RequiresJavaScriptProtocol = true; //加入javascript:头
            String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
            e.Row.Attributes.Add("onclick", evt);
            #endregion
        }
    }

    //索引变更事件--为选择的索引行的所有单元格 绑定单击功能（文本框显示单元格的行、列）
    protected void gv_Size_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        this.gv_Size.SelectedIndex = e.NewSelectedIndex;
        int index = e.NewSelectedIndex;
        string rid = (index + 1).ToString(); //行号
        //GV.Rows[index].BackColor = System.Drawing.Color.FromName("#CCCCCC"); //选中的行显示灰色

        for (int i = 0; i < this.gv_Size.Rows[index].Cells.Count; i++)
        {

            //列的数据获取处理 列从1开始
            //if (i < 2)
            //{
            //    iLcol = 1;
            //}
            //else
            //{
            //    iLcol = i - 1;
            //}

            //列的数据获取处理 列从2开始
            if (i < 2)
            {
                iLcol = 2;
            }
            else
            {
                iLcol = i ;
            }

            //this.gv_Size.Rows[index].Cells[i].Attributes["onclick"] = "ShowEdit(" + Nova_MOD_TBase_Position.No_Lane + "," + Nova_MOD_TBase_Position.No_Line + "," + Nova_MOD_TBase_Position.No_Col + "," + Nova_MOD_TBase_Position.No_Layer + "," + rid + ");";
            this.gv_Size.Rows[index].Cells[i].Attributes["onclick"] = "showEdit(" + iLcol + "," + rid + ");";

        }
    }


    /// <summary>
    /// 巷道下拉列表绑定
    /// </summary>
    protected void ddlNo_Lane_Bind()
    {
        ds = Nova_BLL_TLaneDefine.DataSetTLaneDefine();
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            ddlNo_Lane.DataSource = ds;
            ddlNo_Lane.DataValueField = "No_Lane";
            ddlNo_Lane.DataTextField = "No_Lane_Text";
            ddlNo_Lane.DataBind();
        }
    }

    /// <summary>
    /// 巷道改变时gv发生改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlNo_Lane_SelectedIndexChanged(object sender, EventArgs e)
    {
        gv_Size_Bind();
    }
    /// <summary>
    /// 重新设定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnReset_Size_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (ddlType_Size.SelectedValue == "-1")
            {
                lblKindMessage.Text = "操作失败!请选择货位尺寸类型!";
            }
            else
            {
                if (txtSLine.Text != "" || txtSLcol.Text != "")
                {
                    _SLine = Convert.ToInt32(txtSLine.Text.ToString());
                    _SLcol = Convert.ToInt32(txtSLcol.Text.ToString());

                    if (txtELine.Text != "" || txtELcol.Text != "")
                    {
                        _ELine = Convert.ToInt32(txtELine.Text.ToString());
                        _ELcol = Convert.ToInt32(txtELcol.Text.ToString());
                        iLine = 0;
                        iLcol = 0;

                        if (_SLine > _ELine)
                        {
                            iLine = _SLine;
                            _SLine = _ELine;
                            _ELine = iLine;
                        }
                        if (_SLcol > _ELcol)
                        {
                            iLcol = _SLcol;
                            _SLcol = _ELcol;
                            _ELcol = iLcol;
                        }

                        for (int i = 0; i <= gv_Size.Rows.Count; i++)
                        {
                            if (i >= Convert.ToInt32(_SLine) && i <= Convert.ToInt32(_ELine))
                            {
                                for (int j = 0; j < iCount; j++)
                                {
                                    if (j >= Convert.ToInt32(_SLcol) && j <= Convert.ToInt32(_ELcol))
                                    {
                                        //巷道iPid、排iNo_Line、列iNo_Col、层iNo_Layer
                                        Nova_MOD_TBase_Position.No_Lane = Convert.ToInt32(ddlNo_Lane.SelectedValue);
                                        Nova_MOD_TBase_Position.No_Line = Convert.ToInt32(gv_Size.Rows[i - 1].Cells[0].Text.ToString());
                                        Nova_MOD_TBase_Position.No_Col = j;
                                        Nova_MOD_TBase_Position.No_Layer = Convert.ToInt32(gv_Size.Rows[i - 1].Cells[1].Text.ToString());

                                        iMessage = Nova_BLL_TBase_Position.UpdateTBase_Position(Nova_MOD_TBase_Position, "TypeOfSize", ddlType_Size.SelectedValue);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //巷道iPid、排iNo_Line、列iNo_Col、层iNo_Layer
                        Nova_MOD_TBase_Position.No_Lane = Convert.ToInt32(ddlNo_Lane.SelectedValue);
                        Nova_MOD_TBase_Position.No_Line = Convert.ToInt32(gv_Size.Rows[Convert.ToInt32(_SLine) - 1].Cells[0].Text.ToString());
                        Nova_MOD_TBase_Position.No_Col = Convert.ToInt32(_SLcol);
                        Nova_MOD_TBase_Position.No_Layer = Convert.ToInt32(gv_Size.Rows[Convert.ToInt32(_SLine) - 1].Cells[1].Text.ToString());

                        iMessage = Nova_BLL_TBase_Position.UpdateTBase_Position(Nova_MOD_TBase_Position, "TypeOfSize", ddlType_Size.SelectedValue);
                    }
                    if (iMessage == 1)
                    {
                        lblKindMessage.Text = "操作成功!";

                        gv_Size_Bind();
                    }
                    else
                    {
                        lblKindMessage.Text = "操作失败!";
                    }
                }
            }
            txtELcol.Text = "";
            txtELine.Text = "";
            txtSLcol.Text = "";
            txtSLine.Text = "";
            gv_Size_Bind();
        }
        catch (Exception ex)
        {
            lblKindMessage.Text = "异常跳出!";
        }
    }

    /// <summary>
    /// 删除限制
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnDel_Size_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (txtSLine.Text != "" || txtSLcol.Text != "")
            {
                _SLine = Convert.ToInt32(txtSLine.Text.ToString());
                _SLcol = Convert.ToInt32(txtSLcol.Text.ToString());

                if (txtELine.Text != "" || txtELcol.Text != "")
                {
                    _ELine = Convert.ToInt32(txtELine.Text.ToString());
                    _ELcol = Convert.ToInt32(txtELcol.Text.ToString());
                    iLine = 0;
                    iLcol = 0;

                    if (_SLine > _ELine)
                    {
                        iLine = _SLine;
                        _SLine = _ELine;
                        _ELine = iLine;
                    }
                    if (_SLcol > _ELcol)
                    {
                        iLcol = _SLcol;
                        _SLcol = _ELcol;
                        _ELcol = iLcol;
                    }

                    for (int i = 0; i <= gv_Size.Rows.Count; i++)
                    {
                        if (i >= Convert.ToInt32(_SLine) && i <= Convert.ToInt32(_ELine))
                        {
                            for (int j = 0; j < iCount - 1; j++)
                            {
                                if (j >= Convert.ToInt32(_SLcol) && j <= Convert.ToInt32(_ELcol))
                                {
                                    //巷道iPid、排iNo_Line、列iNo_Col、层iNo_Layer
                                    Nova_MOD_TBase_Position.No_Lane = Convert.ToInt32(ddlNo_Lane.SelectedValue);
                                    Nova_MOD_TBase_Position.No_Line = Convert.ToInt32(gv_Size.Rows[i - 1].Cells[0].Text.ToString());
                                    Nova_MOD_TBase_Position.No_Col = j;
                                    Nova_MOD_TBase_Position.No_Layer = Convert.ToInt32(gv_Size.Rows[i - 1].Cells[1].Text.ToString());

                                    iMessage = Nova_BLL_TBase_Position.UpdateTBase_Position(Nova_MOD_TBase_Position, "TypeOfSize", "0");
                                }
                            }
                        }
                    }
                }
                else
                {
                    //巷道iPid、排iNo_Line、列iNo_Col、层iNo_Layer
                    Nova_MOD_TBase_Position.No_Lane = Convert.ToInt32(ddlNo_Lane.SelectedValue);
                    Nova_MOD_TBase_Position.No_Line = Convert.ToInt32(gv_Size.Rows[Convert.ToInt32(_SLine) - 1].Cells[0].Text.ToString());
                    Nova_MOD_TBase_Position.No_Col = Convert.ToInt32(_SLcol);
                    Nova_MOD_TBase_Position.No_Layer = Convert.ToInt32(gv_Size.Rows[Convert.ToInt32(_SLine) - 1].Cells[1].Text.ToString());

                    iMessage = Nova_BLL_TBase_Position.UpdateTBase_Position(Nova_MOD_TBase_Position, "TypeOfSize", "0");
                }
                if (iMessage == 1)
                {
                    lblKindMessage.Text = "操作成功!";
                    ibtnReset_Click(sender, e);
                }
                else
                {
                    lblKindMessage.Text = "操作失败!";
                }
            }
        }
        catch (Exception ex)
        {
            lblKindMessage.Text = "异常跳出!";
        }
    }

    protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
    {
        txtSLcol.Text = "";
        txtSLine.Text = "";
        txtELcol.Text = "";
        txtELine.Text = "";
        lblKindMessage.Text = "";
        gv_Size_Bind();
    }
    /// <summary>
    /// 选中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnSelect_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (txtSLine.Text != "" || txtSLcol.Text != "")
            {
                _SLine = Convert.ToInt32(txtSLine.Text.ToString());
                _SLcol = Convert.ToInt32(txtSLcol.Text.ToString());

                if (txtELine.Text != "" || txtELcol.Text != "")
                {
                    _ELine = Convert.ToInt32(txtELine.Text.ToString());
                    _ELcol = Convert.ToInt32(txtELcol.Text.ToString());
                    iLine = 0;
                    iLcol = 0;

                    if (_SLine > _ELine)
                    {
                        iLine = _SLine;
                        _SLine = _ELine;
                        _ELine = iLine;
                    }
                    if (_SLcol > _ELcol)
                    {
                        iLcol = _SLcol;
                        _SLcol = _ELcol;
                        _ELcol = iLcol;
                    }

                    for (int i = 0; i <= gv_Size.Rows.Count; i++)
                    {
                        if (i >= Convert.ToInt32(_SLine) && i <= Convert.ToInt32(_ELine))
                        {
                            for (int j = 0; j < iCount; j++)
                            {
                                if (j >= Convert.ToInt32(_SLcol) && j <= Convert.ToInt32(_ELcol))
                                {
                                    //gv_Size.Rows[i - 1].Cells[j + 1].BackColor = System.Drawing.Color.FromName("#ff0000");//改变背景色   列从1开始
                                    gv_Size.Rows[i - 1].Cells[j].BackColor = System.Drawing.Color.FromName("#ff0000");//改变背景色  列从2开始
                                }
                            }
                        }
                    }
                }
                else
                {
                    //gv_Size.Rows[Convert.ToInt32(txtSLine.Text) - 1].Cells[Convert.ToInt32(txtSLcol.Text)].BackColor = System.Drawing.Color.FromName("#ff0000");     //改变背景色  列从2开始
                    gv_Size.Rows[Convert.ToInt32(txtSLine.Text) - 1].Cells[Convert.ToInt32(txtSLcol.Text) + 1].BackColor = System.Drawing.Color.FromName("#ff0000"); //改变背景色   列从1开始
                }
            }
        }
        catch (Exception ex)
        {
            lblKindMessage.Text = "异常跳出!";
        }
    }




  
}
